package com.smag.web.controller.echarts.pie;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.smag.echarts.domain.EchartsPieProduct;
import com.smag.echarts.service.IEchartsPieProductService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.smag.common.annotation.Log;
import com.smag.common.core.controller.BaseController;
import com.smag.common.core.domain.AjaxResult;
import com.smag.common.enums.BusinessType;
import com.smag.common.utils.poi.ExcelUtil;
import com.smag.common.core.page.TableDataInfo;

/**
 * 特色农产品Controller
 * 
 * @author ruoyi
 * @date 2023-04-26
 */
@RestController("pieProductController")
@RequestMapping("/echarts/pie/product")
public class ProductController extends BaseController
{
    @Autowired
    private IEchartsPieProductService echartsPieProductService;

    @RequestMapping("/listFirstProduct")
    public AjaxResult listFirstProduct() {
        return success(echartsPieProductService.listFirstProduct());
    }

    /**
     * 查询特色农产品列表
     */
    @PreAuthorize("@ss.hasPermi('system:product:list')")
    @GetMapping("/list")
    public TableDataInfo list(EchartsPieProduct echartsPieProduct)
    {
        startPage();
        List<EchartsPieProduct> list = echartsPieProductService.selectEchartsPieProductList(echartsPieProduct);
        return getDataTable(list);
    }

    /**
     * 导出特色农产品列表
     */
    @PreAuthorize("@ss.hasPermi('system:product:export')")
    @Log(title = "特色农产品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EchartsPieProduct echartsPieProduct)
    {
        List<EchartsPieProduct> list = echartsPieProductService.selectEchartsPieProductList(echartsPieProduct);
        ExcelUtil<EchartsPieProduct> util = new ExcelUtil<EchartsPieProduct>(EchartsPieProduct.class);
        util.exportExcel(response, list, "特色农产品数据");
    }

    /**
     * 获取特色农产品详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:product:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(echartsPieProductService.selectEchartsPieProductById(id));
    }

    /**
     * 新增特色农产品
     */
    @PreAuthorize("@ss.hasPermi('system:product:add')")
    @Log(title = "特色农产品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EchartsPieProduct echartsPieProduct)
    {
        return toAjax(echartsPieProductService.insertEchartsPieProduct(echartsPieProduct));
    }

    /**
     * 修改特色农产品
     */
    @PreAuthorize("@ss.hasPermi('system:product:edit')")
    @Log(title = "特色农产品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EchartsPieProduct echartsPieProduct)
    {
        return toAjax(echartsPieProductService.updateEchartsPieProduct(echartsPieProduct));
    }

    /**
     * 删除特色农产品
     */
    @PreAuthorize("@ss.hasPermi('system:product:remove')")
    @Log(title = "特色农产品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(echartsPieProductService.deleteEchartsPieProductByIds(ids));
    }
}
